package com.manopservice.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.manopservice.dao.CarPartDAO;
import com.manopservice.model.CarPart;
import com.manopservice.model.ResultPagination;

@Service("carPartService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class CarPartServiceImpl implements CarPartService {

	@Autowired
	private CarPartDAO carPartDAO;
	
	public CarPartServiceImpl(){		
	}
	
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void saveCarPart(CarPart carPart) {
		carPartDAO.save(carPart);		
	}
	
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void deleteCarPart(int id) {
		carPartDAO.delete(id);
		
	}

	public List<CarPart> listCarParts() {
		return carPartDAO.findAll();
	}

	@Override
	public CarPart findById(int id) {
		return carPartDAO.findById(id);
	}

	@Override
	public ResultPagination<?> findByModel(String modelName, int pageSelect, int paging) {
		
		return carPartDAO.findByModel(modelName, pageSelect, paging);
	}

}
